package liangtWorkSpace.springAll.ioc;

import liangtWorkSpace.springAll.ioc.dao.HelloWorld;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @author liangt
 * @ClassName: MainApp
 * @title: MainApp
 * @projectName liangtWorkSpace.springAll.ioc
 * @description: TODO
 * @date 2020/10/15 16:03
 */
public class MainApp {

    public static void main(String[] args) {
        String xmlPath = "ioc/Beans.xml";

        ApplicationContext applicationContext = new ClassPathXmlApplicationContext(xmlPath);

        // 演示singleton单例模式，每次请求都是同一个Bean
        HelloWorld helloWorld = (HelloWorld) applicationContext.getBean("helloWorld");
        HelloWorld helloWorld2 = (HelloWorld) applicationContext.getBean("helloWorld");

        helloWorld.setMessage("Hello World!");
        helloWorld.getMessage();
        helloWorld2.getMessage();

        //演示Protytype原型模式，每次请求都是同一个新的Bean
        HelloWorld helloWorldPrototypeOne = (HelloWorld) applicationContext.getBean("helloWorldPrototype");
        helloWorldPrototypeOne.setMessage("Helle prototype!");
        HelloWorld helloWorldPrototypeTow = (HelloWorld) applicationContext.getBean("helloWorldPrototype");
        helloWorldPrototypeOne.getMessage();
        helloWorldPrototypeTow.getMessage();
    }

}
